package com.mixpanel.example.hello;

import android.support.multidex.MultiDexApplication;
import android.text.TextUtils;
import android.util.Log;

import com.mixpanel.android.mpmetrics.MixpanelAPI;
import com.mixpanel.android.util.AssetsHelper;
import com.mixpanel.android.util.L;
import com.mixpanel.android.util.SP;
import com.mixpanel.android.util.T;
import com.tencent.mta.track.StatisticsDataAPI;

import java.io.FileInputStream;
import java.io.IOException;

import app.heatmap.HeatMap;
import app.heatmap.SCallBack;
import app.heatmap.ids.SystemIds;

/**
 * @Copyright © 2018 EGuan Inc. All rights reserved.
 * @Description: TODO
 * @Version: 1.0
 * @Create: 18/3/13 18:11
 * @Author: sanbo
 */
public class App extends MultiDexApplication {
    // aaa
    //public static final String MIXPANEL_API_TOKEN = "f581869b45cb5425fb4b9313dc68a52f";
    //public static final String ANDROID_PUSH_SENDER_ID = "f8e6780c15c0fe656ac8fb28d4ad9dcf";
    // analysys-use
    public static final String MIXPANEL_API_TOKEN = "196d71cb8a0c8c862973e6dd3b51af85";
    public static final String ANDROID_PUSH_SENDER_ID = "716efdd030ddd9a18ca0531450c42b1b";
    //weitao
//    public static final String MIXPANEL_API_TOKEN = "cba3e0b25b88d270fbde3afdfb3a706f";
//    public static final String ANDROID_PUSH_SENDER_ID = "066820eab4abb2970f7d55b74f5de3d0";

    //hello token
    //public static final String MIXPANEL_API_TOKEN = "b887c74b1edb8896188375d9fe8b62cc";
    //public static final String ANDROID_PUSH_SENDER_ID = "9c71d716c9be4f15c831aa1289d152d0";

    public static MixpanelAPI mMixpanel;

    @Override
    public void onCreate() {
        super.onCreate();
        initMixpanel();
        initLib();
        initMta();
        test();
        HeatMap.getInstance(this).init();
    }


    private void initMixpanel() {
        mMixpanel = MixpanelAPI.getInstance(this, MIXPANEL_API_TOKEN);
        mMixpanel.getPeople().initPushHandling(ANDROID_PUSH_SENDER_ID);
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    mMixpanel.track("application onCreate..." + System.currentTimeMillis());
                }
            }
        }).start();
    }

    private void initLib() {
        SP.init(this);
        T.init(this);
    }

    private void test() {
        //        try {
//            Log.i("xx", "-------11111----");
//            String s = AssetsHelper.getFromAssetsToString(this, "s.txt");
//            Log.i("xx", "-------2222----" +s);
//            s =s.replaceAll("\\\\n","");
//            Log.i("xx", "-------3333----" +s);
//            String ttttt =new String(android.util.Base64.decode(s.getBytes(),android.util.Base64.DEFAULT));
//            Log.i("xx", "text:" + ttttt);
//        } catch (Throwable e) {
//            Log.i("xx", Log.getStackTraceString(e));
//        }
//        Log.i("xx", "-------4444----");
    }

    private void initMta() {
        StatisticsDataAPI.instance(this);
    }
}
